<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionView::Helpers::FormBuilder</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            ActionView::Helpers::FormBuilder 
            
                <span class="parent">&lt; 
                    
                    <a href="../../Object.html">Object</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/actionpack/lib/action_view/helpers/date_helper_rb.html">actionpack/lib/action_view/helpers/date_helper.rb</a></li>
            
            <li><a href="../../../files/actionpack/lib/action_view/helpers/form_helper_rb.html">actionpack/lib/action_view/helpers/form_helper.rb</a></li>
            
            <li><a href="../../../files/actionpack/lib/action_view/helpers/form_options_helper_rb.html">actionpack/lib/action_view/helpers/form_options_helper.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>A <code>FormBuilder</code> object is associated with a particular model
object and allows you to generate fields associated with the model object.
The <code>FormBuilder</code> object is yielded when using
<code>form_for</code> or <code>fields_for</code>. For example:</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  Name: &lt;%= person_form.text_field :name %&gt;
  Admin: &lt;%= person_form.check_box :admin %&gt;
&lt;% end %&gt;</pre>

<p>In the above block, the a <code>FormBuilder</code> object is yielded as the
<code>person_form</code> variable. This allows you to generate the
<code>text_field</code> and <code>check_box</code> fields by specifying
their eponymous methods, which modify the underlying template and
associates the +@person+ model object with the form.</p>

<p>The <code>FormBuilder</code> object can be thought of as serving as a proxy
for the methods in the <code>FormHelper</code> module. This class, however,
allows you to call methods with the model object you are building the form
for.</p>

<p>You can create your own custom <a href="FormBuilder.html">FormBuilder</a>
templates by subclasses this class. For example:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">MyFormBuilder</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActionView</span><span class="ruby-operator">::</span><span class="ruby-constant">Helpers</span><span class="ruby-operator">::</span><span class="ruby-constant">FormBuilder</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">div_radio_button</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">tag_value</span>, <span class="ruby-identifier">options</span> = {})
    <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">content_tag</span>(:<span class="ruby-identifier">div</span>,
      <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">radio_button</span>(
        <span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">tag_value</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>)
      )
    )
  <span class="ruby-keyword">end</span>
</pre>

<p>The above code creates a new method <code>div_radio_button</code> which
wraps a div around the a new radio button. Note that when options are
passed in, you must called <code>objectify_options</code> in order for the
model object to get correctly passed to the method. If
<code>objectify_options</code> is not called, then the newly created helper
will not be linked back to the model.</p>

<p>The <code>div_radio_button</code> code from above can now be used as
follows:</p>

<pre>&lt;%= form_for @person, :builder =&gt; MyFormBuilder do |f| %&gt;
  I am a child: &lt;%= f.div_radio_button(:admin, &quot;child&quot;) %&gt;
  I am an adult: &lt;%= f.div_radio_button(:admin, &quot;adult&quot;) %&gt;
&lt;% end -%&gt;</pre>

<p>The standard set of helper methods for form building are located in the
<code>field_helpers</code> class attribute.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>#</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-c-_to_partial_path">_to_partial_path</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>B</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-button">button</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-check_box">check_box</a>,
              </li>
            
              
              <li>
                <a href="FormBuilder.html#method-i-collection_check_boxes">collection_check_boxes</a>,
              </li>
            
              
              <li>
                <a href="FormBuilder.html#method-i-collection_radio_buttons">collection_radio_buttons</a>,
              </li>
            
              
              <li>
                <a href="FormBuilder.html#method-i-collection_select">collection_select</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-date_select">date_select</a>,
              </li>
            
              
              <li>
                <a href="FormBuilder.html#method-i-datetime_select">datetime_select</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-emitted_hidden_id-3F">emitted_hidden_id?</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>F</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-fields_for">fields_for</a>,
              </li>
            
              
              <li>
                <a href="FormBuilder.html#method-i-file_field">file_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>G</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-grouped_collection_select">grouped_collection_select</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>H</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-hidden_field">hidden_field</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>L</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-label">label</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>M</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-multipart-3D">multipart=</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>R</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-radio_button">radio_button</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-select">select</a>,
              </li>
            
              
              <li>
                <a href="FormBuilder.html#method-i-submit">submit</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>T</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="FormBuilder.html#method-i-time_select">time_select</a>,
              </li>
            
              
              <li>
                <a href="FormBuilder.html#method-i-time_zone_select">time_zone_select</a>,
              </li>
            
              
              <li>
                <a href="FormBuilder.html#method-i-to_model">to_model</a>,
              </li>
            
              
              <li>
                <a href="FormBuilder.html#method-i-to_partial_path">to_partial_path</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  
    <!-- Includes -->
    <div class="sectiontitle">Included Modules</div>
    <ul>
      
        <li>
          
            <a href="../ModelNaming.html">
              ActionView::ModelNaming
            </a>
          
        </li>
      
    </ul>
  



  

    

    

    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>index</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>multipart</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>multipart?</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>object</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>object_name</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>options</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-_to_partial_path">
            
              <b>_to_partial_path</b>()
            
            <a href="FormBuilder.html#method-c-_to_partial_path" name="method-c-_to_partial_path" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-_to_partial_path_source')" id="l_method-c-_to_partial_path_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1228" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-_to_partial_path_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1228</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">self</span>.<span class="ruby-identifier">_to_partial_path</span>
  <span class="ruby-ivar">@_to_partial_path</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">demodulize</span>.<span class="ruby-identifier">underscore</span>.<span class="ruby-identifier">sub!</span>(<span class="ruby-regexp">/_builder$/</span>, <span class="ruby-string">''</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(object_name, object, template, options, block=nil)
            
            <a href="FormBuilder.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1240" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1240</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">object</span>, <span class="ruby-identifier">template</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">block</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">block</span>
    <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Deprecation</span>.<span class="ruby-identifier">warn</span> <span class="ruby-string">&quot;Giving a block to FormBuilder is deprecated and has no effect anymore.&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-ivar">@nested_child_index</span> = {}
  <span class="ruby-ivar">@object_name</span>, <span class="ruby-ivar">@object</span>, <span class="ruby-ivar">@template</span>, <span class="ruby-ivar">@options</span> = <span class="ruby-identifier">object_name</span>, <span class="ruby-identifier">object</span>, <span class="ruby-identifier">template</span>, <span class="ruby-identifier">options</span>
  <span class="ruby-ivar">@default_options</span> = <span class="ruby-ivar">@options</span> <span class="ruby-operator">?</span> <span class="ruby-ivar">@options</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-value">:index</span>, <span class="ruby-value">:namespace</span>) <span class="ruby-operator">:</span> {}
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@object_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">/\[\]$/</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">object</span> <span class="ruby-operator">||=</span> <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-node">&quot;@#{Regexp.last_match.pre_match}&quot;</span>) <span class="ruby-keyword">and</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:to_param</span>)
      <span class="ruby-ivar">@auto_index</span> = <span class="ruby-identifier">object</span>.<span class="ruby-identifier">to_param</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@multipart</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-ivar">@index</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:index</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:child_index</span>]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-button">
            
              <b>button</b>(value = nil, options = {}, &amp;block)
            
            <a href="FormBuilder.html#method-i-button" name="method-i-button" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Add the submit button for the given form. When no value is given, it checks
if the object is a new resource or not to create the proper label:</p>

<pre>&lt;%= form_for @post do |f| %&gt;
  &lt;%= f.button %&gt;
&lt;% end %&gt;</pre>

<p>In the example above, if @post is a new record, it will use “Create Post”
as button label, otherwise, it uses “Update Post”.</p>

<p>Those labels can be customized using <a href="../../I18n.html">I18n</a>,
under the helpers.submit key (the same as submit helper) and accept the
%{model} as translation interpolation:</p>

<pre>en:
  helpers:
    submit:
      create: &quot;Create a %{model}&quot;
      update: &quot;Confirm changes to %{model}&quot;</pre>

<p>It also searches for a key specific for the given object:</p>

<pre>en:
  helpers:
    submit:
      post:
        create: &quot;Add %{model}&quot;</pre>

<h4 id="method-i-button-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">button</span>(<span class="ruby-string">&quot;Create a post&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;button name='button' type='submit'&gt;Create post&lt;/button&gt;</span>

<span class="ruby-identifier">button</span> <span class="ruby-keyword">do</span>
  <span class="ruby-identifier">content_tag</span>(:<span class="ruby-identifier">strong</span>, <span class="ruby-string">'Ask me!'</span>)
<span class="ruby-keyword">end</span>
<span class="ruby-comment"># =&gt; &lt;button name='button' type='submit'&gt;</span>
<span class="ruby-comment">#      &lt;strong&gt;Ask me!&lt;/strong&gt;</span>
<span class="ruby-comment">#    &lt;/button&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-button_source')" id="l_method-i-button_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1797" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-button_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1797</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">button</span>(<span class="ruby-identifier">value</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = {}, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">value</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
  <span class="ruby-identifier">value</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">submit_default_value</span>
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">button_tag</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">options</span>, &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-check_box">
            
              <b>check_box</b>(method, options = {}, checked_value = &quot;1&quot;, unchecked_value = &quot;0&quot;)
            
            <a href="FormBuilder.html#method-i-check_box" name="method-i-check_box" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a checkbox tag tailored for accessing a specified attribute
(identified by <code>method</code>) on an object assigned to the template
(identified by <code>object</code>). This object must be an instance object
(@object) and not a local object. It’s intended that <code>method</code>
returns an integer and if that integer is above zero, then the checkbox is
checked. Additional options on the input tag can be passed as a hash with
<code>options</code>. The <code>checked_value</code> defaults to 1 while
the default <code>unchecked_value</code> is set to 0 which is convenient
for boolean values.</p>

<h4 id="method-i-check_box-label-Gotcha">Gotcha</h4>

<p>The <a href="../../HTML.html">HTML</a> specification says unchecked check
boxes are not successful, and thus web browsers do not send them.
Unfortunately this introduces a gotcha: if an <code>Invoice</code> model
has a <code>paid</code> flag, and in the form that edits a paid invoice the
user unchecks its check box, no <code>paid</code> parameter is sent. So,
any mass-assignment idiom like</p>

<pre>@invoice.update(params[:invoice])</pre>

<p>wouldn’t update the flag.</p>

<p>To prevent this the helper generates an auxiliary hidden field before the
very check box. The hidden field has the same name and its attributes mimic
an unchecked check box.</p>

<p>This way, the client either sends only the hidden field (representing the
check box is unchecked), or both fields. Since the <a
href="../../HTML.html">HTML</a> specification says key/value pairs have to
be sent in the same order they appear in the form, and parameters
extraction gets the last occurrence of any repeated key in the query
string, that works for ordinary forms.</p>

<p>Unfortunately that workaround does not work when the check box goes within
an array-like parameter, as in</p>

<pre>&lt;%= fields_for &quot;project[invoice_attributes][]&quot;, invoice, index: nil do |form| %&gt;
  &lt;%= form.check_box :paid %&gt;
  ...
&lt;% end %&gt;</pre>

<p>because parameter name repetition is precisely what <a
href="../../Rails.html">Rails</a> seeks to distinguish the elements of the
array. For each item with a checked check box you get an extra ghost item
with only that attribute, assigned to “0”.</p>

<p>In that case it is preferable to either use <code>check_box_tag</code> or
to use hashes instead of arrays.</p>

<pre class="ruby"><span class="ruby-comment"># Let's say that @post.validated? is 1:</span>
<span class="ruby-identifier">check_box</span>(<span class="ruby-string">&quot;post&quot;</span>, <span class="ruby-string">&quot;validated&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input name=&quot;post[validated]&quot; type=&quot;hidden&quot; value=&quot;0&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input checked=&quot;checked&quot; type=&quot;checkbox&quot; id=&quot;post_validated&quot; name=&quot;post[validated]&quot; value=&quot;1&quot; /&gt;</span>

<span class="ruby-comment"># Let's say that @puppy.gooddog is &quot;no&quot;:</span>
<span class="ruby-identifier">check_box</span>(<span class="ruby-string">&quot;puppy&quot;</span>, <span class="ruby-string">&quot;gooddog&quot;</span>, {}, <span class="ruby-string">&quot;yes&quot;</span>, <span class="ruby-string">&quot;no&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input name=&quot;puppy[gooddog]&quot; type=&quot;hidden&quot; value=&quot;no&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input type=&quot;checkbox&quot; id=&quot;puppy_gooddog&quot; name=&quot;puppy[gooddog]&quot; value=&quot;yes&quot; /&gt;</span>

<span class="ruby-identifier">check_box</span>(<span class="ruby-string">&quot;eula&quot;</span>, <span class="ruby-string">&quot;accepted&quot;</span>, { <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">'eula_check'</span> }, <span class="ruby-string">&quot;yes&quot;</span>, <span class="ruby-string">&quot;no&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input name=&quot;eula[accepted]&quot; type=&quot;hidden&quot; value=&quot;no&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input type=&quot;checkbox&quot; class=&quot;eula_check&quot; id=&quot;eula_accepted&quot; name=&quot;eula[accepted]&quot; value=&quot;yes&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-check_box_source')" id="l_method-i-check_box_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1648" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-check_box_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1648</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">check_box</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">checked_value</span> = <span class="ruby-string">&quot;1&quot;</span>, <span class="ruby-identifier">unchecked_value</span> = <span class="ruby-string">&quot;0&quot;</span>)
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">check_box</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-identifier">checked_value</span>, <span class="ruby-identifier">unchecked_value</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-collection_check_boxes">
            
              <b>collection_check_boxes</b>(method, collection, value_method, text_method, options = {}, html_options = {}, &amp;block)
            
            <a href="FormBuilder.html#method-i-collection_check_boxes" name="method-i-collection_check_boxes" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Wraps <a
href="FormOptionsHelper.html#method-i-collection_check_boxes">ActionView::Helpers::FormOptionsHelper#collection_check_boxes</a>
for form builders:</p>

<pre>&lt;%= form_for @post do |f| %&gt;
  &lt;%= f.collection_check_boxes :author_ids, Author.all, :id, :name_with_initial %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>Please refer to the documentation of the base helper for details.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-collection_check_boxes_source')" id="l_method-i-collection_check_boxes_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0778290b57433da3bcd707fce222b8f646b7de4f/actionpack/lib/action_view/helpers/form_options_helper.rb#L816" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-collection_check_boxes_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_options_helper.rb, line 816</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">collection_check_boxes</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">collection</span>, <span class="ruby-identifier">value_method</span>, <span class="ruby-identifier">text_method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {}, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">collection_check_boxes</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">collection</span>, <span class="ruby-identifier">value_method</span>, <span class="ruby-identifier">text_method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-ivar">@default_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">html_options</span>), &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-collection_radio_buttons">
            
              <b>collection_radio_buttons</b>(method, collection, value_method, text_method, options = {}, html_options = {}, &amp;block)
            
            <a href="FormBuilder.html#method-i-collection_radio_buttons" name="method-i-collection_radio_buttons" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Wraps <a
href="FormOptionsHelper.html#method-i-collection_radio_buttons">ActionView::Helpers::FormOptionsHelper#collection_radio_buttons</a>
for form builders:</p>

<pre>&lt;%= form_for @post do |f| %&gt;
  &lt;%= f.collection_radio_buttons :author_id, Author.all, :id, :name_with_initial %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>Please refer to the documentation of the base helper for details.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-collection_radio_buttons_source')" id="l_method-i-collection_radio_buttons_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0778290b57433da3bcd707fce222b8f646b7de4f/actionpack/lib/action_view/helpers/form_options_helper.rb#L828" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-collection_radio_buttons_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_options_helper.rb, line 828</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">collection_radio_buttons</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">collection</span>, <span class="ruby-identifier">value_method</span>, <span class="ruby-identifier">text_method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {}, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">collection_radio_buttons</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">collection</span>, <span class="ruby-identifier">value_method</span>, <span class="ruby-identifier">text_method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-ivar">@default_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">html_options</span>), &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-collection_select">
            
              <b>collection_select</b>(method, collection, value_method, text_method, options = {}, html_options = {})
            
            <a href="FormBuilder.html#method-i-collection_select" name="method-i-collection_select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Wraps <a
href="FormOptionsHelper.html#method-i-collection_select">ActionView::Helpers::FormOptionsHelper#collection_select</a>
for form builders:</p>

<pre>&lt;%= form_for @post do |f| %&gt;
  &lt;%= f.collection_select :person_id, Author.all, :id, :name_with_initial, prompt: true %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>Please refer to the documentation of the base helper for details.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-collection_select_source')" id="l_method-i-collection_select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0778290b57433da3bcd707fce222b8f646b7de4f/actionpack/lib/action_view/helpers/form_options_helper.rb#L780" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-collection_select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_options_helper.rb, line 780</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">collection_select</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">collection</span>, <span class="ruby-identifier">value_method</span>, <span class="ruby-identifier">text_method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">collection_select</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">collection</span>, <span class="ruby-identifier">value_method</span>, <span class="ruby-identifier">text_method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-ivar">@default_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">html_options</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-date_select">
            
              <b>date_select</b>(method, options = {}, html_options = {})
            
            <a href="FormBuilder.html#method-i-date_select" name="method-i-date_select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Wraps <a
href="DateHelper.html#method-i-date_select">ActionView::Helpers::DateHelper#date_select</a>
for form builders:</p>

<pre>&lt;%= form_for @person do |f| %&gt;
  &lt;%= f.date_select :birth_date %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>Please refer to the documentation of the base helper for details.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-date_select_source')" id="l_method-i-date_select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L1054" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-date_select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 1054</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">date_select</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">date_select</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-identifier">html_options</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-datetime_select">
            
              <b>datetime_select</b>(method, options = {}, html_options = {})
            
            <a href="FormBuilder.html#method-i-datetime_select" name="method-i-datetime_select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Wraps <a
href="DateHelper.html#method-i-datetime_select">ActionView::Helpers::DateHelper#datetime_select</a>
for form builders:</p>

<pre>&lt;%= form_for @person do |f| %&gt;
  &lt;%= f.time_select :last_request_at %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>Please refer to the documentation of the base helper for details.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-datetime_select_source')" id="l_method-i-datetime_select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L1078" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-datetime_select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 1078</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">datetime_select</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">datetime_select</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-identifier">html_options</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-emitted_hidden_id-3F">
            
              <b>emitted_hidden_id?</b>()
            
            <a href="FormBuilder.html#method-i-emitted_hidden_id-3F" name="method-i-emitted_hidden_id-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-emitted_hidden_id-3F_source')" id="l_method-i-emitted_hidden_id-3F_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1803" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-emitted_hidden_id-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1803</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">emitted_hidden_id?</span>
  <span class="ruby-ivar">@emitted_hidden_id</span> <span class="ruby-operator">||=</span> <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-fields_for">
            
              <b>fields_for</b>(record_name, record_object = nil, fields_options = {}, &amp;block)
            
            <a href="FormBuilder.html#method-i-fields_for" name="method-i-fields_for" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Creates a scope around a specific model object like form_for, but doesn’t
create the form tags themselves. This makes <a
href="FormBuilder.html#method-i-fields_for">#fields_for</a> suitable for
specifying additional model objects in the same form.</p>

<p>Although the usage and purpose of <code>field_for</code> is similar to
<code>form_for</code>‘s, its method signature is slightly different. Like
<code>form_for</code>, it yields a <a
href="FormBuilder.html">FormBuilder</a> object associated with a particular
model object to a block, and within the block allows methods to be called
on the builder to generate fields associated with the model object. Fields
may reflect a model object in two ways - how they are named (hence how
submitted values appear within the <code>params</code> hash in the
controller) and what default values are shown when the form the fields
appear in is first displayed. In order for both of these features to be
specified independently, both an object name (represented by either a
symbol or string) and the object itself can be passed to the method
separately -</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  First name: &lt;%= person_form.text_field :first_name %&gt;
  Last name : &lt;%= person_form.text_field :last_name %&gt;

  &lt;%= fields_for :permission, @person.permission do |permission_fields| %&gt;
    Admin?  : &lt;%= permission_fields.check_box :admin %&gt;
  &lt;% end %&gt;

  &lt;%= person_form.submit %&gt;
&lt;% end %&gt;</pre>

<p>In this case, the checkbox field will be represented by an <a
href="../../HTML.html">HTML</a> <code>input</code> tag with the
<code>name</code> attribute <code>permission[admin]</code>, and the
submitted value will appear in the controller as
<code>params[:permission][:admin]</code>. If
<code>@person.permission</code> is an existing record with an attribute
<code>admin</code>, the initial state of the checkbox when first displayed
will reflect the value of <code>@person.permission.admin</code>.</p>

<p>Often this can be simplified by passing just the name of the model object
to <code>fields_for</code> -</p>

<pre>&lt;%= fields_for :permission do |permission_fields| %&gt;
  Admin?: &lt;%= permission_fields.check_box :admin %&gt;
&lt;% end %&gt;</pre>

<p>…in which case, if <code>:permission</code> also happens to be the name of
an instance variable <code>@permission</code>, the initial state of the
input field will reflect the value of that variable’s attribute
<code>@permission.admin</code>.</p>

<p>Alternatively, you can pass just the model object itself (if the first
argument isn’t a string or symbol <code>fields_for</code> will realize that
the name has been omitted) -</p>

<pre>&lt;%= fields_for @person.permission do |permission_fields| %&gt;
  Admin?: &lt;%= permission_fields.check_box :admin %&gt;
&lt;% end %&gt;</pre>

<p>and <code>fields_for</code> will derive the required name of the field from
the <em>class</em> of the model object, e.g. if
<code>@person.permission</code>, is of class <code>Permission</code>, the
field will still be named <code>permission[admin]</code>.</p>

<p>Note: This also works for the methods in FormOptionHelper and <a
href="DateHelper.html">DateHelper</a> that are designed to work with an
object as base, like FormOptionHelper#collection_select and <a
href="DateHelper.html#method-i-datetime_select">ActionView::Helpers::DateHelper#datetime_select</a>.</p>

<h3 id="method-i-fields_for-label-Nested+Attributes+Examples">Nested Attributes Examples</h3>

<p>When the object belonging to the current scope has a nested attribute
writer for a certain attribute, <a
href="FormBuilder.html#method-i-fields_for">#fields_for</a> will yield a
new scope for that attribute. This allows you to create forms that set or
change the attributes of a parent object and its associations in one go.</p>

<p>Nested attribute writers are normal setter methods named after an
association. The most common way of defining these writers is either with
<code>accepts_nested_attributes_for</code> in a model definition or by
defining a method with the proper name. For example: the attribute writer
for the association <code>:address</code> is called
<code>address_attributes=</code>.</p>

<p>Whether a one-to-one or one-to-many style form builder will be yielded
depends on whether the normal reader method returns a <em>single</em>
object or an <em>array</em> of objects.</p>

<h4 id="method-i-fields_for-label-One-to-one">One-to-one</h4>

<p>Consider a Person class which returns a <em>single</em> Address from the
<code>address</code> reader method and responds to the
<code>address_attributes=</code> writer method:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">address</span>
    <span class="ruby-ivar">@address</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier">address_attributes=</span>(<span class="ruby-identifier">attributes</span>)
    <span class="ruby-comment"># Process the attributes hash</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This model can now be used with a nested <a
href="FormBuilder.html#method-i-fields_for">#fields_for</a>, like so:</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :address do |address_fields| %&gt;
    Street  : &lt;%= address_fields.text_field :street %&gt;
    Zip code: &lt;%= address_fields.text_field :zip_code %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>When address is already an association on a Person you can use
<code>accepts_nested_attributes_for</code> to define the writer method for
you:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_one</span> :<span class="ruby-identifier">address</span>
  <span class="ruby-identifier">accepts_nested_attributes_for</span> :<span class="ruby-identifier">address</span>
<span class="ruby-keyword">end</span>
</pre>

<p>If you want to destroy the associated model through the form, you have to
enable it first using the <code>:allow_destroy</code> option for
<code>accepts_nested_attributes_for</code>:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_one</span> :<span class="ruby-identifier">address</span>
  <span class="ruby-identifier">accepts_nested_attributes_for</span> :<span class="ruby-identifier">address</span>, <span class="ruby-identifier">allow_destroy</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Now, when you use a form element with the <code>_destroy</code> parameter,
with a value that evaluates to <code>true</code>, you will destroy the
associated model (eg. 1, ‘1’, true, or ‘true’):</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :address do |address_fields| %&gt;
    ...
    Delete: &lt;%= address_fields.check_box :_destroy %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<h4 id="method-i-fields_for-label-One-to-many">One-to-many</h4>

<p>Consider a Person class which returns an <em>array</em> of Project
instances from the <code>projects</code> reader method and responds to the
<code>projects_attributes=</code> writer method:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">projects</span>
    [<span class="ruby-ivar">@project1</span>, <span class="ruby-ivar">@project2</span>]
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier">projects_attributes=</span>(<span class="ruby-identifier">attributes</span>)
    <span class="ruby-comment"># Process the attributes hash</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Note that the <code>projects_attributes=</code> writer method is in fact
required for <a href="FormBuilder.html#method-i-fields_for">#fields_for</a>
to correctly identify <code>:projects</code> as a collection, and the
correct indices to be set in the form markup.</p>

<p>When projects is already an association on Person you can use
<code>accepts_nested_attributes_for</code> to define the writer method for
you:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_many</span> :<span class="ruby-identifier">projects</span>
  <span class="ruby-identifier">accepts_nested_attributes_for</span> :<span class="ruby-identifier">projects</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This model can now be used with a nested fields_for. The block given to the
nested <a href="FormBuilder.html#method-i-fields_for">#fields_for</a> call
will be repeated for each instance in the collection:</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :projects do |project_fields| %&gt;
    &lt;% if project_fields.object.active? %&gt;
      Name: &lt;%= project_fields.text_field :name %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>It’s also possible to specify the instance to be used:</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;% @person.projects.each do |project| %&gt;
    &lt;% if project.active? %&gt;
      &lt;%= person_form.fields_for :projects, project do |project_fields| %&gt;
        Name: &lt;%= project_fields.text_field :name %&gt;
      &lt;% end %&gt;
    &lt;% end %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>Or a collection to be used:</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :projects, @active_projects do |project_fields| %&gt;
    Name: &lt;%= project_fields.text_field :name %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>If you want to destroy any of the associated models through the form, you
have to enable it first using the <code>:allow_destroy</code> option for
<code>accepts_nested_attributes_for</code>:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Person</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_many</span> :<span class="ruby-identifier">projects</span>
  <span class="ruby-identifier">accepts_nested_attributes_for</span> :<span class="ruby-identifier">projects</span>, <span class="ruby-identifier">allow_destroy</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span>
</pre>

<p>This will allow you to specify which models to destroy in the attributes
hash by adding a form element for the <code>_destroy</code> parameter with
a value that evaluates to <code>true</code> (eg. 1, ‘1’, true, or ‘true’):</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :projects do |project_fields| %&gt;
    Delete: &lt;%= project_fields.check_box :_destroy %&gt;
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>When a collection is used you might want to know the index of each object
into the array. For this purpose, the <code>index</code> method is
available in the <a href="FormBuilder.html">FormBuilder</a> object.</p>

<pre>&lt;%= form_for @person do |person_form| %&gt;
  ...
  &lt;%= person_form.fields_for :projects do |project_fields| %&gt;
    Project #&lt;%= project_fields.index %&gt;
    ...
  &lt;% end %&gt;
  ...
&lt;% end %&gt;</pre>

<p>Note that <a href="FormBuilder.html#method-i-fields_for">#fields_for</a>
will automatically generate a hidden field to store the ID of the record.
There are circumstances where this hidden field is not needed and you can
pass <code>hidden_field_id: false</code> to prevent <a
href="FormBuilder.html#method-i-fields_for">#fields_for</a> from rendering
it automatically.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-fields_for_source')" id="l_method-i-fields_for_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1512" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-fields_for_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1512</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">fields_for</span>(<span class="ruby-identifier">record_name</span>, <span class="ruby-identifier">record_object</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">fields_options</span> = {}, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">fields_options</span>, <span class="ruby-identifier">record_object</span> = <span class="ruby-identifier">record_object</span>, <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">record_object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">record_object</span>.<span class="ruby-identifier">extractable_options?</span>
  <span class="ruby-identifier">fields_options</span>[<span class="ruby-value">:builder</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:builder</span>]
  <span class="ruby-identifier">fields_options</span>[<span class="ruby-value">:namespace</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-value">:namespace</span>]
  <span class="ruby-identifier">fields_options</span>[<span class="ruby-value">:parent_builder</span>] = <span class="ruby-keyword">self</span>

  <span class="ruby-keyword">case</span> <span class="ruby-identifier">record_name</span>
  <span class="ruby-keyword">when</span> <span class="ruby-constant">String</span>, <span class="ruby-constant">Symbol</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">nested_attributes_association?</span>(<span class="ruby-identifier">record_name</span>)
      <span class="ruby-keyword">return</span> <span class="ruby-identifier">fields_for_with_nested_attributes</span>(<span class="ruby-identifier">record_name</span>, <span class="ruby-identifier">record_object</span>, <span class="ruby-identifier">fields_options</span>, <span class="ruby-identifier">block</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">record_object</span> = <span class="ruby-identifier">record_name</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">record_name</span>.<span class="ruby-identifier">last</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">record_name</span>
    <span class="ruby-identifier">record_name</span>   = <span class="ruby-identifier">model_name_from_record_or_class</span>(<span class="ruby-identifier">record_object</span>).<span class="ruby-identifier">param_key</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">index</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value">:index</span>)
    <span class="ruby-identifier">options</span>[<span class="ruby-value">:index</span>]
  <span class="ruby-keyword">elsif</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-ivar">@auto_index</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">object_name</span> = <span class="ruby-ivar">@object_name</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\[\]$/</span>,<span class="ruby-string">&quot;&quot;</span>)
    <span class="ruby-ivar">@auto_index</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">record_name</span> = <span class="ruby-identifier">index</span> <span class="ruby-operator">?</span> <span class="ruby-node">&quot;#{object_name}[#{index}][#{record_name}]&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-node">&quot;#{object_name}[#{record_name}]&quot;</span>
  <span class="ruby-identifier">fields_options</span>[<span class="ruby-value">:child_index</span>] = <span class="ruby-identifier">index</span>

  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">fields_for</span>(<span class="ruby-identifier">record_name</span>, <span class="ruby-identifier">record_object</span>, <span class="ruby-identifier">fields_options</span>, &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-file_field">
            
              <b>file_field</b>(method, options = {})
            
            <a href="FormBuilder.html#method-i-file_field" name="method-i-file_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a file upload input tag tailored for accessing a specified
attribute (identified by <code>method</code>) on an object assigned to the
template (identified by <code>object</code>). Additional options on the
input tag can be passed as a hash with <code>options</code>. These options
will be tagged onto the <a href="../../HTML.html">HTML</a> as an <a
href="../../HTML.html">HTML</a> element attribute as in the example shown.</p>

<p>Using this method inside a <code>form_for</code> block will set the
enclosing form’s encoding to <code>multipart/form-data</code>.</p>

<h4 id="method-i-file_field-label-Options">Options</h4>
<ul><li>
<p>Creates standard <a href="../../HTML.html">HTML</a> attributes for the tag.</p>
</li><li>
<p><code>:disabled</code> - If set to true, the user will not be able to use
this input.</p>
</li><li>
<p><code>:multiple</code> - If set to true, *in most updated browsers* the
user will be allowed to select multiple files.</p>
</li><li>
<p><code>:accept</code> - If set to one or multiple mime-types, the user will
be suggested a filter when choosing a file. You still need to set up model
validations.</p>
</li></ul>

<h4 id="method-i-file_field-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">avatar</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;file&quot; id=&quot;user_avatar&quot; name=&quot;user[avatar]&quot; /&gt;</span>

<span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">image</span>, :<span class="ruby-identifier">multiple</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">true</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;file&quot; id=&quot;post_image&quot; name=&quot;post[image]&quot; multiple=&quot;true&quot; /&gt;</span>

<span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">attached</span>, <span class="ruby-identifier">accept</span><span class="ruby-operator">:</span> <span class="ruby-string">'text/html'</span>)
<span class="ruby-comment"># =&gt; &lt;input accept=&quot;text/html&quot; type=&quot;file&quot; id=&quot;post_attached&quot; name=&quot;post[attached]&quot; /&gt;</span>

<span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">image</span>, <span class="ruby-identifier">accept</span><span class="ruby-operator">:</span> <span class="ruby-string">'image/png,image/gif,image/jpeg'</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;file&quot; id=&quot;post_image&quot; name=&quot;post[image]&quot; accept=&quot;image/png,image/gif,image/jpeg&quot; /&gt;</span>

<span class="ruby-identifier">file_field</span>(:<span class="ruby-identifier">attachment</span>, :<span class="ruby-identifier">file</span>, <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">'file_input'</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;file&quot; id=&quot;attachment_file&quot; name=&quot;attachment[file]&quot; class=&quot;file_input&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-file_field_source')" id="l_method-i-file_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1721" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-file_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1721</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">file_field</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">multipart</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">file_field</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-grouped_collection_select">
            
              <b>grouped_collection_select</b>(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
            
            <a href="FormBuilder.html#method-i-grouped_collection_select" name="method-i-grouped_collection_select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Wraps <a
href="FormOptionsHelper.html#method-i-grouped_collection_select">ActionView::Helpers::FormOptionsHelper#grouped_collection_select</a>
for form builders:</p>

<pre>&lt;%= form_for @city do |f| %&gt;
  &lt;%= f.grouped_collection_select :country_id, :country_id, @continents, :countries, :name, :id, :name %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>Please refer to the documentation of the base helper for details.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-grouped_collection_select_source')" id="l_method-i-grouped_collection_select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0778290b57433da3bcd707fce222b8f646b7de4f/actionpack/lib/action_view/helpers/form_options_helper.rb#L792" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-grouped_collection_select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_options_helper.rb, line 792</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">grouped_collection_select</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">collection</span>, <span class="ruby-identifier">group_method</span>, <span class="ruby-identifier">group_label_method</span>, <span class="ruby-identifier">option_key_method</span>, <span class="ruby-identifier">option_value_method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">grouped_collection_select</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">collection</span>, <span class="ruby-identifier">group_method</span>, <span class="ruby-identifier">group_label_method</span>, <span class="ruby-identifier">option_key_method</span>, <span class="ruby-identifier">option_value_method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-ivar">@default_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">html_options</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-hidden_field">
            
              <b>hidden_field</b>(method, options = {})
            
            <a href="FormBuilder.html#method-i-hidden_field" name="method-i-hidden_field" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a hidden input tag tailored for accessing a specified attribute
(identified by <code>method</code>) on an object assigned to the template
(identified by <code>object</code>). Additional options on the input tag
can be passed as a hash with <code>options</code>. These options will be
tagged onto the <a href="../../HTML.html">HTML</a> as an <a
href="../../HTML.html">HTML</a> element attribute as in the example shown.</p>

<h4 id="method-i-hidden_field-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">hidden_field</span>(:<span class="ruby-identifier">signup</span>, :<span class="ruby-identifier">pass_confirm</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;hidden&quot; id=&quot;signup_pass_confirm&quot; name=&quot;signup[pass_confirm]&quot; value=&quot;#{@signup.pass_confirm}&quot; /&gt;</span>

<span class="ruby-identifier">hidden_field</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">tag_list</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;hidden&quot; id=&quot;post_tag_list&quot; name=&quot;post[tag_list]&quot; value=&quot;#{@post.tag_list}&quot; /&gt;</span>

<span class="ruby-identifier">hidden_field</span>(:<span class="ruby-identifier">user</span>, :<span class="ruby-identifier">token</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;hidden&quot; id=&quot;user_token&quot; name=&quot;user[token]&quot; value=&quot;#{@user.token}&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-hidden_field_source')" id="l_method-i-hidden_field_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1688" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-hidden_field_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1688</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">hidden_field</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-ivar">@emitted_hidden_id</span> = <span class="ruby-keyword">true</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">method</span> <span class="ruby-operator">==</span> <span class="ruby-value">:id</span>
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">hidden_field</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-label">
            
              <b>label</b>(method, text = nil, options = {}, &amp;block)
            
            <a href="FormBuilder.html#method-i-label" name="method-i-label" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a label tag tailored for labelling an input field for a specified
attribute (identified by <code>method</code>) on an object assigned to the
template (identified by <code>object</code>). The text of label will
default to the attribute name unless a translation is found in the current
<a href="../../I18n.html">I18n</a> locale (through
helpers.label.&lt;modelname&gt;.&lt;attribute&gt;) or you specify it
explicitly. Additional options on the label tag can be passed as a hash
with <code>options</code>. These options will be tagged onto the <a
href="../../HTML.html">HTML</a> as an <a href="../../HTML.html">HTML</a>
element attribute as in the example shown, except for the
<code>:value</code> option, which is designed to target labels for <a
href="FormBuilder.html#method-i-radio_button">#radio_button</a> tags (where
the value is used in the ID of the input tag).</p>

<h4 id="method-i-label-label-Examples">Examples</h4>

<pre class="ruby"><span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">title</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_title&quot;&gt;Title&lt;/label&gt;</span>
</pre>

<p>You can localize your labels based on model and attribute names. For
example you can define the following in your locale (e.g. en.yml)</p>

<pre>helpers:
  label:
    post:
      body: &quot;Write your entire text here&quot;</pre>

<p>Which then will result in</p>

<pre class="ruby"><span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">body</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_body&quot;&gt;Write your entire text here&lt;/label&gt;</span>
</pre>

<p>Localization can also be based purely on the translation of the
attribute-name (if you are using <a
href="../../ActiveRecord.html">ActiveRecord</a>):</p>

<pre class="ruby"><span class="ruby-identifier">activerecord</span><span class="ruby-operator">:</span>
  <span class="ruby-identifier">attributes</span><span class="ruby-operator">:</span>
    <span class="ruby-identifier">post</span><span class="ruby-operator">:</span>
      <span class="ruby-identifier">cost</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;Total cost&quot;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">cost</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_cost&quot;&gt;Total cost&lt;/label&gt;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">title</span>, <span class="ruby-string">&quot;A short title&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_title&quot;&gt;A short title&lt;/label&gt;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">title</span>, <span class="ruby-string">&quot;A short title&quot;</span>, <span class="ruby-identifier">class</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;title_label&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_title&quot; class=&quot;title_label&quot;&gt;A short title&lt;/label&gt;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">privacy</span>, <span class="ruby-string">&quot;Public Post&quot;</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;public&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;label for=&quot;post_privacy_public&quot;&gt;Public Post&lt;/label&gt;</span>

<span class="ruby-identifier">label</span>(:<span class="ruby-identifier">post</span>, :<span class="ruby-identifier">terms</span>) <span class="ruby-keyword">do</span>
  <span class="ruby-string">'Accept &lt;a href=&quot;/terms&quot;&gt;Terms&lt;/a&gt;.'</span>.<span class="ruby-identifier">html_safe</span>
<span class="ruby-keyword">end</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-label_source')" id="l_method-i-label_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1588" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-label_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1588</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">label</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">text</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = {}, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">label</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">text</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-multipart-3D">
            
              <b>multipart=</b>(multipart)
            
            <a href="FormBuilder.html#method-i-multipart-3D" name="method-i-multipart-3D" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-multipart-3D_source')" id="l_method-i-multipart-3D_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1220" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-multipart-3D_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1220</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">multipart=</span>(<span class="ruby-identifier">multipart</span>)
  <span class="ruby-ivar">@multipart</span> = <span class="ruby-identifier">multipart</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">parent_builder</span> = <span class="ruby-ivar">@options</span>[<span class="ruby-value">:parent_builder</span>]
    <span class="ruby-identifier">parent_builder</span>.<span class="ruby-identifier">multipart</span> = <span class="ruby-identifier">multipart</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-radio_button">
            
              <b>radio_button</b>(method, tag_value, options = {})
            
            <a href="FormBuilder.html#method-i-radio_button" name="method-i-radio_button" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns a radio button tag for accessing a specified attribute (identified
by <code>method</code>) on an object assigned to the template (identified
by <code>object</code>). If the current value of <code>method</code> is
<code>tag_value</code> the radio button will be checked.</p>

<p>To force the radio button to be checked pass <code>checked: true</code> in
the <code>options</code> hash. You may pass <a
href="../../HTML.html">HTML</a> options there as well.</p>

<pre class="ruby"><span class="ruby-comment"># Let's say that @post.category returns &quot;rails&quot;:</span>
<span class="ruby-identifier">radio_button</span>(<span class="ruby-string">&quot;post&quot;</span>, <span class="ruby-string">&quot;category&quot;</span>, <span class="ruby-string">&quot;rails&quot;</span>)
<span class="ruby-identifier">radio_button</span>(<span class="ruby-string">&quot;post&quot;</span>, <span class="ruby-string">&quot;category&quot;</span>, <span class="ruby-string">&quot;java&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;radio&quot; id=&quot;post_category_rails&quot; name=&quot;post[category]&quot; value=&quot;rails&quot; checked=&quot;checked&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input type=&quot;radio&quot; id=&quot;post_category_java&quot; name=&quot;post[category]&quot; value=&quot;java&quot; /&gt;</span>

<span class="ruby-identifier">radio_button</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;receive_newsletter&quot;</span>, <span class="ruby-string">&quot;yes&quot;</span>)
<span class="ruby-identifier">radio_button</span>(<span class="ruby-string">&quot;user&quot;</span>, <span class="ruby-string">&quot;receive_newsletter&quot;</span>, <span class="ruby-string">&quot;no&quot;</span>)
<span class="ruby-comment"># =&gt; &lt;input type=&quot;radio&quot; id=&quot;user_receive_newsletter_yes&quot; name=&quot;user[receive_newsletter]&quot; value=&quot;yes&quot; /&gt;</span>
<span class="ruby-comment">#    &lt;input type=&quot;radio&quot; id=&quot;user_receive_newsletter_no&quot; name=&quot;user[receive_newsletter]&quot; value=&quot;no&quot; checked=&quot;checked&quot; /&gt;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-radio_button_source')" id="l_method-i-radio_button_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1669" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-radio_button_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1669</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">radio_button</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">tag_value</span>, <span class="ruby-identifier">options</span> = {})
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">radio_button</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">tag_value</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-select">
            
              <b>select</b>(method, choices, options = {}, html_options = {})
            
            <a href="FormBuilder.html#method-i-select" name="method-i-select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Wraps <a
href="FormOptionsHelper.html#method-i-select">ActionView::Helpers::FormOptionsHelper#select</a>
for form builders:</p>

<pre>&lt;%= form_for @post do |f| %&gt;
  &lt;%= f.select :person_id, Person.all.collect {|p| [ p.name, p.id ] }, { include_blank: true }) %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>Please refer to the documentation of the base helper for details.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-select_source')" id="l_method-i-select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0778290b57433da3bcd707fce222b8f646b7de4f/actionpack/lib/action_view/helpers/form_options_helper.rb#L768" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_options_helper.rb, line 768</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">select</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">choices</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">select</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">choices</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-ivar">@default_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">html_options</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-submit">
            
              <b>submit</b>(value=nil, options={})
            
            <a href="FormBuilder.html#method-i-submit" name="method-i-submit" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Add the submit button for the given form. When no value is given, it checks
if the object is a new resource or not to create the proper label:</p>

<pre>&lt;%= form_for @post do |f| %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>In the example above, if @post is a new record, it will use “Create Post”
as submit button label, otherwise, it uses “Update Post”.</p>

<p>Those labels can be customized using <a href="../../I18n.html">I18n</a>,
under the helpers.submit key and accept the %{model} as translation
interpolation:</p>

<pre>en:
  helpers:
    submit:
      create: &quot;Create a %{model}&quot;
      update: &quot;Confirm changes to %{model}&quot;</pre>

<p>It also searches for a key specific for the given object:</p>

<pre>en:
  helpers:
    submit:
      post:
        create: &quot;Add %{model}&quot;</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-submit_source')" id="l_method-i-submit_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1753" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-submit_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1753</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">submit</span>(<span class="ruby-identifier">value</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span>={})
  <span class="ruby-identifier">value</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
  <span class="ruby-identifier">value</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">submit_default_value</span>
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">submit_tag</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">options</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-time_select">
            
              <b>time_select</b>(method, options = {}, html_options = {})
            
            <a href="FormBuilder.html#method-i-time_select" name="method-i-time_select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Wraps <a
href="DateHelper.html#method-i-time_select">ActionView::Helpers::DateHelper#time_select</a>
for form builders:</p>

<pre>&lt;%= form_for @race do |f| %&gt;
  &lt;%= f.time_select :average_lap %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>Please refer to the documentation of the base helper for details.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-time_select_source')" id="l_method-i-time_select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/c52c2682bf03192755ccf8c15ab641090815cacf/actionpack/lib/action_view/helpers/date_helper.rb#L1066" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-time_select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/date_helper.rb, line 1066</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">time_select</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">time_select</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-identifier">html_options</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-time_zone_select">
            
              <b>time_zone_select</b>(method, priority_zones = nil, options = {}, html_options = {})
            
            <a href="FormBuilder.html#method-i-time_zone_select" name="method-i-time_zone_select" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Wraps <a
href="FormOptionsHelper.html#method-i-time_zone_select">ActionView::Helpers::FormOptionsHelper#time_zone_select</a>
for form builders:</p>

<pre>&lt;%= form_for @user do |f| %&gt;
  &lt;%= f.time_zone_select :time_zone, nil, include_blank: true %&gt;
  &lt;%= f.submit %&gt;
&lt;% end %&gt;</pre>

<p>Please refer to the documentation of the base helper for details.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-time_zone_select_source')" id="l_method-i-time_zone_select_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/0778290b57433da3bcd707fce222b8f646b7de4f/actionpack/lib/action_view/helpers/form_options_helper.rb#L804" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-time_zone_select_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_options_helper.rb, line 804</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">time_zone_select</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">priority_zones</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">options</span> = {}, <span class="ruby-identifier">html_options</span> = {})
  <span class="ruby-ivar">@template</span>.<span class="ruby-identifier">time_zone_select</span>(<span class="ruby-ivar">@object_name</span>, <span class="ruby-identifier">method</span>, <span class="ruby-identifier">priority_zones</span>, <span class="ruby-identifier">objectify_options</span>(<span class="ruby-identifier">options</span>), <span class="ruby-ivar">@default_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">html_options</span>))
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-to_model">
            
              <b>to_model</b>()
            
            <a href="FormBuilder.html#method-i-to_model" name="method-i-to_model" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-to_model_source')" id="l_method-i-to_model_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1236" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-to_model_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1236</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">to_model</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-to_partial_path">
            
              <b>to_partial_path</b>()
            
            <a href="FormBuilder.html#method-i-to_partial_path" name="method-i-to_partial_path" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-to_partial_path_source')" id="l_method-i-to_partial_path_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/fb24f419051aec00790a8e6fb5785eeb6f503f4a/actionpack/lib/action_view/helpers/form_helper.rb#L1232" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-to_partial_path_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionpack/lib/action_view/helpers/form_helper.rb, line 1232</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">to_partial_path</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">_to_partial_path</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    